import React from 'react'
// ===================================================================== temp
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy, $config, $http } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const PageFull 	= $Lazy.load(()=>import('#tp/page/page-full'))
const AddLast 	= $Lazy.load(()=>import('@cpt/add-last'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: []
	}
	
	componentDidMount(){
		const { spec_num, spec_nums } = $fn.query()
		
		const type = $config.getEnv()
		
		const { reportUrl, reportPath } = window.globalConfig

		// $http.submit(null,'kd-report-spec/reportDetails', { param:{spec_num}, isPull:true }).then(({ report_path })=>{
		// 	this.refs.iframe.src =  report_path ? report_path : `${$config.reportUrl(type)}&rno=${spec_num}&type=${type}`
		// })
		if(type === 2){ // 预览增加验证 2022-1-20 6:09:10 ?F10: PM? --伍智睿
			$http.submit(null,'index/getReportSign', { param:{spec_num}, isPull:true }).then(({sign})=>{
				$http.submit(null, reportPath + '/token', { param:{token:sign}, isPull:true }).then(token=>{
					this.refs.iframe.src =  `${reportUrl}&token=${token}&rno=${spec_num ?? spec_nums}&type=${type}`
				})
			})
		}else{
			setTimeout(() => this.refs.iframe.src =  `${reportUrl}&rno=${spec_num ?? spec_nums}&type=${type}`, 200)
		}
		
		// $http.submit(this,'/api/kd-report-spec/reportInfo', { param:{spec_num}, dataName:null, isPull:true })
		
	}
	
	// 操作按钮
	controls = [
		Controls.back.call(this)
	]
	
	render(){
		const { src } = this.state
		return (
			<AddLast name='预览报告单'>
				<PageFull>
					<Page full title='预览报告单' controls={ this.controls }>
						<div className='ex rel'>
							<iframe ref='iframe' title='预览报告单' className='abs_full wh' src={src} />
						</div>
					</Page>
				</PageFull>
			</AddLast>
		)
	}
}

export default Index